home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / MEMCHR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  896 b   |  27 lines

  1. /* memchr.c, from p.149 of Turbo C Bible  */
  2. /*  Searches for a specific character in
  3.     a given number of bytes of the buffer  */
  4. /* Use the large memory model (-ml flag)       */
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <mem.h>
  8. /* Copyright notice begins at segment F000 and offset E000 */
  9. #define  COPYRIGHT_NOTICE  MK_FP(0Xf000,0Xe000)
  10. static char dest[81];               /* Destination buffer */
  11. main()
  12. {
  13.     void *copr_address, *first_i;
  14.     copr_address = COPYRIGHT_NOTICE;
  15.     if((first_i = memchr(copr_address, 'I', 24)) == NULL)
  16.                         /* Look for the 'I' */
  17.     {                                      /*   of IBM in the copyright notice */
  18.         printf("Search failed!\n");
  19.     }
  20.     else
  21.     {
  22.         printf("Found an 'I' at %p\n", first_i);
  23.         memcpy(dest, first_i, 8);/* Copy next 8 characters into */
  24.         dest[8] = '\0';        /* buffer 'dest' for printing */
  25.         printf("The next 8 characters are: %s\n", dest);
  26.     }
  27. }